//
//  WJConstants.swift
//  PDFSign
//
//  Created by 李永彬 on 2025/9/18.
//

import UIKit

let guideKey = "guideKey"
let isFirstPurchaseKey = "isFirstPurchaseKey"

let tabBarHeight = 72.0;
let kScreenWidth: CGFloat = UIScreen.main.bounds.width
let kScreenHeight: CGFloat = UIScreen.main.bounds.height
let aScale = kScreenWidth / 375.0
let signatureBoxSize = CGSize(width: 180.0, height: 123.0)

extension UIWindow {
    /// 全局安全区域（兼容 iOS 11+）
    static var safeAreaInsets: UIEdgeInsets {
        if #available(iOS 11.0, *) {
            return UIApplication.shared.windows.first?.safeAreaInsets ?? .zero
        } else {
            return .zero
        }
    }
}

var safeAreaBottom: CGFloat {
    return UIWindow.safeAreaInsets.bottom
}

var safeAreaTop: CGFloat {
    return UIWindow.safeAreaInsets.top
}

func setCustomTabBarHidden(_ hidden: Bool) {
    guard let window = UIApplication.shared.currentWindow else {
        return
    }
    
    if let mainVC = window.rootViewController as? WJMainTabViewController {
        mainVC.setCustomTabBarHidden(hidden)
    }
}

func formatTimestamp(_ timestamp: TimeInterval) -> String {
    let date = Date(timeIntervalSince1970: timestamp)
    let formatter = DateFormatter()
    
    // 设置日期格式为 "日 月 年"
    formatter.dateFormat = "MMMM d,yyyy"
    
    return formatter.string(from: date)
}

func formatFileSize(bits: Double) -> String {
    let units = ["bits", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"]
    var size = bits
    var unitIndex = 0
    
    while size >= 1000 && unitIndex < units.count - 1 {
        size /= 1000
        unitIndex += 1
    }
    
    return String(format: "%.2f %@", size, units[unitIndex])
}

